package com.yixun.qfbao.hander;

import com.yixun.qfbao.api.service.PremisesApiService;
import com.yixun.qfbao.apidto.SetPremisesOrderReqDto;
import com.yixun.qfbao.apidto.SetPremisesOrderResDto;
import com.yixun.qfbao.dto.base.BaseRequestDTO;
import com.yixun.qfbao.dto.base.BaseResponseDTO;
import com.yixun.qfbao.hander.base.CommonAbstractHander;
import com.yixun.qfbao.util.exception.TServerException;
import com.yixun.qfbao.vo.SetPremisesOrderReqVo;
import com.yixun.qfbao.xf.model.enums.ResultEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SetPremisesOrderHander extends CommonAbstractHander {
    private static Logger logger= LoggerFactory.getLogger(SetPremisesOrderHander.class);

    @Autowired
    private PremisesApiService premisesApiService;

    @Override
    public BaseResponseDTO doBusiness(BaseRequestDTO reqDto) {
        SetPremisesOrderReqVo setPremisesOrderReqVo = (SetPremisesOrderReqVo) reqDto;
        SetPremisesOrderReqDto setPremisesOrderReqDto = setPremisesOrderReqVo.getParams();
        BaseResponseDTO<SetPremisesOrderResDto> res = new BaseResponseDTO<>();
        try {
            SetPremisesOrderResDto resDto = premisesApiService.setPremisesOrder(setPremisesOrderReqDto);
            res.setResult(resDto.getResult());
            res.setErrorMsg(resDto.getResultMsg());
        } catch (TServerException e) {
            logger.error("SetPremisesOrderHander error: {}", e);
            res.setResult(ResultEnum.FAIL.getNo());
            res.setErrorMsg(e.getMessage());
        } catch (Exception e) {
            logger.error("SetPremisesOrderHander error: {}", e);
            res.setResult(ResultEnum.FAIL.getNo());
            res.setErrorMsg("操作失败");
        }
        return res;
    }
}
